/**
* This file is part of tictionary.
*
* tictionary is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with dev.clipall.  If not, see <http://www.gnu.org/licenses/>.
*
* http://code.google.com/p/tictionary/
*/

package tictionary;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.netbeans.microedition.lcdui.WaitScreen;
import org.netbeans.microedition.util.SimpleCancellableTask;

/**
 * @author Erol Hira
 */
public class TictionaryMIDlet extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    
    private String developer;
    private String dict_owner;
    private String dictNote;
    private String dev_mail;
    
    private ImageScreen imgScr;
    
// HINT - Uncomment for accessing new MIDlet Started/Resumed logic.
//    private boolean midletPaused = false;

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Image image1;
    private Image image;
    private SimpleCancellableTask task1;
    private SimpleCancellableTask task;
    private Command Ara;
    private Command commandMean;
    private Command Geri;
    private Command Tamam1;
    private Command commandExit;
    private Command commandAdvancedSearch;
    private Command Tamam;
    private Command commandAbout;
    private Command EVET;
    private Command HAYIR;
    private List resultList;
    private Form form1;
    private Spacer spacer;
    private TextField textField;
    private WaitScreen waitScreen1;
    private Alert meanAlert;
    private Alert alert1;
    private Form form;
    private Spacer spacer1;
    private Spacer spacer2;
    private Spacer spacer3;
    private StringItem stringItem_note;
    private StringItem stringItem_owner;
    private StringItem stringItem2;
    private StringItem stringItem_developer;
    //</editor-fold>//GEN-END:|fields|0|


// HINT - Uncomment for accessing new MIDlet Started/Resumed logic.
// NOTE - Be aware of resolving conflicts of the constructor.
//    /**
//     * The ConvertedTictionaryMIDlet constructor.
//     */
//    public ConvertedTictionaryMIDlet() {
//    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getWaitScreen1());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: Ara ">//GEN-BEGIN:|15-getter|0|15-preInit
    /**
     * Returns an initiliazed instance of Ara component.
     * @return the initialized component instance
     */
    public Command getAra() {
        if (Ara == null) {//GEN-END:|15-getter|0|15-preInit
            // Insert pre-init code here
            Ara = new Command("Ara", Command.OK, 1);//GEN-LINE:|15-getter|1|15-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|15-getter|2|
        return Ara;
    }
    //</editor-fold>//GEN-END:|15-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: commandExit ">//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of commandExit component.
     * @return the initialized component instance
     */
    public Command getCommandExit() {
        if (commandExit == null) {//GEN-END:|18-getter|0|18-preInit
            // Insert pre-init code here
            commandExit = new Command("\u00C7IKI\u015E", Command.EXIT, 1);//GEN-LINE:|18-getter|1|18-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|18-getter|2|
        return commandExit;
    }
    //</editor-fold>//GEN-END:|18-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: EVET ">//GEN-BEGIN:|21-getter|0|21-preInit
    /**
     * Returns an initiliazed instance of EVET component.
     * @return the initialized component instance
     */
    public Command getEVET() {
        if (EVET == null) {//GEN-END:|21-getter|0|21-preInit
            // Insert pre-init code here
            EVET = new Command("EVET", Command.OK, 1);//GEN-LINE:|21-getter|1|21-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|21-getter|2|
        return EVET;
    }
    //</editor-fold>//GEN-END:|21-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: HAYIR ">//GEN-BEGIN:|24-getter|0|24-preInit
    /**
     * Returns an initiliazed instance of HAYIR component.
     * @return the initialized component instance
     */
    public Command getHAYIR() {
        if (HAYIR == null) {//GEN-END:|24-getter|0|24-preInit
            // Insert pre-init code here
            HAYIR = new Command("HAYIR", Command.BACK, 1);//GEN-LINE:|24-getter|1|24-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|24-getter|2|
        return HAYIR;
    }
    //</editor-fold>//GEN-END:|24-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: commandAdvancedSearch ">//GEN-BEGIN:|28-getter|0|28-preInit
    /**
     * Returns an initiliazed instance of commandAdvancedSearch component.
     * @return the initialized component instance
     */
    public Command getCommandAdvancedSearch() {
        if (commandAdvancedSearch == null) {//GEN-END:|28-getter|0|28-preInit
            // Insert pre-init code here
            commandAdvancedSearch = new Command("Geli\u015Fmi\u015F Arama", Command.OK, 2);//GEN-LINE:|28-getter|1|28-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|28-getter|2|
        return commandAdvancedSearch;
    }
    //</editor-fold>//GEN-END:|28-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: commandMean ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of commandMean component.
     * @return the initialized component instance
     */
    public Command getCommandMean() {
        if (commandMean == null) {//GEN-END:|34-getter|0|34-preInit
            // Insert pre-init code here
            commandMean = new Command("Anlam\u0131", Command.OK, 1);//GEN-LINE:|34-getter|1|34-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|34-getter|2|
        return commandMean;
    }
    //</editor-fold>//GEN-END:|34-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: Tamam ">//GEN-BEGIN:|37-getter|0|37-preInit
    /**
     * Returns an initiliazed instance of Tamam component.
     * @return the initialized component instance
     */
    public Command getTamam() {
        if (Tamam == null) {//GEN-END:|37-getter|0|37-preInit
            // Insert pre-init code here
            Tamam = new Command("Tamam", Command.OK, 1);//GEN-LINE:|37-getter|1|37-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|37-getter|2|
        return Tamam;
    }
    //</editor-fold>//GEN-END:|37-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: Geri ">//GEN-BEGIN:|41-getter|0|41-preInit
    /**
     * Returns an initiliazed instance of Geri component.
     * @return the initialized component instance
     */
    public Command getGeri() {
        if (Geri == null) {//GEN-END:|41-getter|0|41-preInit
            // Insert pre-init code here
            Geri = new Command("Geri", Command.BACK, 1);//GEN-LINE:|41-getter|1|41-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|41-getter|2|
        return Geri;
    }
    //</editor-fold>//GEN-END:|41-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
    // Insert global pre-action code here
        if (displayable == alert1) {//GEN-BEGIN:|7-commandAction|1|20-preAction
            if (command == EVET) {//GEN-END:|7-commandAction|1|20-preAction
                // Insert pre-action code here
                exitMIDlet();//GEN-LINE:|7-commandAction|2|20-postAction
                // Insert post-action code here
            } else if (command == HAYIR) {//GEN-LINE:|7-commandAction|3|23-preAction
                // Insert pre-action code here
                switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|4|23-postAction
                // Insert post-action code here
            }//GEN-BEGIN:|7-commandAction|5|84-preAction
        } else if (displayable == form) {
            if (command == Tamam1) {//GEN-END:|7-commandAction|5|84-preAction
                // write pre-action user code here
                switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|6|84-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|7|14-preAction
        } else if (displayable == form1) {
            if (command == Ara) {//GEN-END:|7-commandAction|7|14-preAction
                // Insert pre-action code here
                searchText();
                switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|8|14-postAction
                // Insert post-action code here
            } else if (command == commandAbout) {//GEN-LINE:|7-commandAction|9|73-preAction
                // write pre-action user code here
                getStringItem_developer().setText(
                        developer + " (" + dev_mail + ")"
                        );
                getStringItem_owner().setText(dict_owner);
                getStringItem_note().setText(dictNote);
                switchDisplayable(null, getForm());//GEN-LINE:|7-commandAction|10|73-postAction
                // write post-action user code here
            } else if (command == commandAdvancedSearch) {//GEN-LINE:|7-commandAction|11|27-preAction
                // Insert pre-action code here
                searchAdvanced();
//GEN-LINE:|7-commandAction|12|27-postAction
                // Insert post-action code here
            } else if (command == commandExit) {//GEN-LINE:|7-commandAction|13|17-preAction
                // Insert pre-action code here
                switchDisplayable(getAlert1(), getForm1());//GEN-LINE:|7-commandAction|14|17-postAction
                // Insert post-action code here
            }//GEN-BEGIN:|7-commandAction|15|36-preAction
        } else if (displayable == meanAlert) {
            if (command == Tamam) {//GEN-END:|7-commandAction|15|36-preAction
                // Insert pre-action code here
                switchDisplayable(null, getResultList());//GEN-LINE:|7-commandAction|16|36-postAction
                // Insert post-action code here
            }//GEN-BEGIN:|7-commandAction|17|40-preAction
        } else if (displayable == resultList) {
            if (command == Geri) {//GEN-END:|7-commandAction|17|40-preAction
                // Insert pre-action code here
                clearMeanItems();
                switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|18|40-postAction
                // Insert post-action code here
            } else if (command == List.SELECT_COMMAND) {//GEN-LINE:|7-commandAction|19|31-preAction
                // write pre-action user code here
                resultListAction();//GEN-LINE:|7-commandAction|20|31-postAction
                // write post-action user code here
            } else if (command == commandMean) {//GEN-LINE:|7-commandAction|21|33-preAction
                // Insert pre-action code here
                
                String mean = getMean();
                
                getMeanAlert().setTitle(getResultList().getString(getResultList().getSelectedIndex()));
                getMeanAlert().setString(mean);
                
                switchDisplayable(getMeanAlert(), getResultList());//GEN-LINE:|7-commandAction|22|33-postAction
                // Insert post-action code here
            }//GEN-BEGIN:|7-commandAction|23|89-preAction
        } else if (displayable == waitScreen1) {
            if (command == WaitScreen.FAILURE_COMMAND) {//GEN-END:|7-commandAction|23|89-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|24|89-postAction
                // write post-action user code here
            } else if (command == WaitScreen.SUCCESS_COMMAND) {//GEN-LINE:|7-commandAction|25|88-preAction
                // write pre-action user code here
                switchDisplayable(null, getForm1());//GEN-LINE:|7-commandAction|26|88-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|27|7-postCommandAction
        }//GEN-END:|7-commandAction|27|7-postCommandAction
    // Insert global post-action code here
    }//GEN-BEGIN:|7-commandAction|28|
    //</editor-fold>//GEN-END:|7-commandAction|28|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form1 ">//GEN-BEGIN:|13-getter|0|13-preInit
    /**
     * Returns an initiliazed instance of form1 component.
     * @return the initialized component instance
     */
    public Form getForm1() {
        if (form1 == null) {//GEN-END:|13-getter|0|13-preInit
            // Insert pre-init code here
            form1 = new Form("Osmanl\u0131ca-T\u00FCrk\u00E7e", new Item[] { getTextField(), getSpacer() });//GEN-BEGIN:|13-getter|1|13-postInit
            form1.addCommand(getAra());
            form1.addCommand(getCommandExit());
            form1.addCommand(getCommandAdvancedSearch());
            form1.addCommand(getCommandAbout());
            form1.setCommandListener(this);//GEN-END:|13-getter|1|13-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|13-getter|2|
        return form1;
    }
    //</editor-fold>//GEN-END:|13-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: alert1 ">//GEN-BEGIN:|19-getter|0|19-preInit
    /**
     * Returns an initiliazed instance of alert1 component.
     * @return the initialized component instance
     */
    public Alert getAlert1() {
        if (alert1 == null) {//GEN-END:|19-getter|0|19-preInit
            // Insert pre-init code here
            alert1 = new Alert("UYARI", "Uygulamadan \u00E7\u0131kmak istiyor musunuz ?", null, null);//GEN-BEGIN:|19-getter|1|19-postInit
            alert1.addCommand(getEVET());
            alert1.addCommand(getHAYIR());
            alert1.setCommandListener(this);
            alert1.setTimeout(Alert.FOREVER);//GEN-END:|19-getter|1|19-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|19-getter|2|
        return alert1;
    }
    //</editor-fold>//GEN-END:|19-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: resultList ">//GEN-BEGIN:|29-getter|0|29-preInit
    /**
     * Returns an initiliazed instance of resultList component.
     * @return the initialized component instance
     */
    public List getResultList() {
        if (resultList == null) {//GEN-END:|29-getter|0|29-preInit
            // Insert pre-init code here
            resultList = new List("list", Choice.IMPLICIT);//GEN-BEGIN:|29-getter|1|29-postInit
            resultList.addCommand(getCommandMean());
            resultList.addCommand(getGeri());
            resultList.setCommandListener(this);
            resultList.setSelectCommand(getCommandMean());//GEN-END:|29-getter|1|29-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|29-getter|2|
        return resultList;
    }
    //</editor-fold>//GEN-END:|29-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resultListAction ">//GEN-BEGIN:|29-action|0|29-preAction
    /**
     * Performs an action assigned to the selected list element in the resultList component.
     */
    public void resultListAction() {//GEN-END:|29-action|0|29-preAction
        // enter pre-action user code here
//GEN-LINE:|29-action|1|29-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|29-action|2|
    //</editor-fold>//GEN-END:|29-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: meanAlert ">//GEN-BEGIN:|35-getter|0|35-preInit
    /**
     * Returns an initiliazed instance of meanAlert component.
     * @return the initialized component instance
     */
    public Alert getMeanAlert() {
        if (meanAlert == null) {//GEN-END:|35-getter|0|35-preInit
            // Insert pre-init code here
            meanAlert = new Alert("alert", "<Enter Text>", null, null);//GEN-BEGIN:|35-getter|1|35-postInit
            meanAlert.addCommand(getTamam());
            meanAlert.setCommandListener(this);
            meanAlert.setTimeout(Alert.FOREVER);//GEN-END:|35-getter|1|35-postInit
            // Insert post-init code here
        }//GEN-BEGIN:|35-getter|2|
        return meanAlert;
    }
    //</editor-fold>//GEN-END:|35-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField ">//GEN-BEGIN:|50-getter|0|50-preInit
    /**
     * Returns an initiliazed instance of textField component.
     * @return the initialized component instance
     */
    public TextField getTextField() {
        if (textField == null) {//GEN-END:|50-getter|0|50-preInit
            // write pre-init user code here
            textField = new TextField("Ara", "", 32, TextField.ANY);//GEN-BEGIN:|50-getter|1|50-postInit
            textField.setLayout(ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);//GEN-END:|50-getter|1|50-postInit
            // write post-init user code here
        }//GEN-BEGIN:|50-getter|2|
        return textField;
    }
    //</editor-fold>//GEN-END:|50-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task ">//GEN-BEGIN:|67-getter|0|67-preInit
    /**
     * Returns an initiliazed instance of task component.
     * @return the initialized component instance
     */
    public SimpleCancellableTask getTask() {
        if (task == null) {//GEN-END:|67-getter|0|67-preInit
            // write pre-init user code here
            task = new SimpleCancellableTask();//GEN-BEGIN:|67-getter|1|67-execute
            task.setExecutable(new org.netbeans.microedition.util.Executable() {
                public void execute() throws Exception {//GEN-END:|67-getter|1|67-execute
                    
                }//GEN-BEGIN:|67-getter|2|67-postInit
            });//GEN-END:|67-getter|2|67-postInit
            // write post-init user code here
        }//GEN-BEGIN:|67-getter|3|
        return task;
    }
    //</editor-fold>//GEN-END:|67-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: spacer ">//GEN-BEGIN:|71-getter|0|71-preInit
    /**
     * Returns an initiliazed instance of spacer component.
     * @return the initialized component instance
     */
    public Spacer getSpacer() {
        if (spacer == null) {//GEN-END:|71-getter|0|71-preInit
            // write pre-init user code here
            spacer = new Spacer(16, 6);//GEN-BEGIN:|71-getter|1|71-postInit
            spacer.setLayout(ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            spacer.setPreferredSize(-1, 6);//GEN-END:|71-getter|1|71-postInit
            // write post-init user code here
        }//GEN-BEGIN:|71-getter|2|
        return spacer;
    }
    //</editor-fold>//GEN-END:|71-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: commandAbout ">//GEN-BEGIN:|72-getter|0|72-preInit
    /**
     * Returns an initiliazed instance of commandAbout component.
     * @return the initialized component instance
     */
    public Command getCommandAbout() {
        if (commandAbout == null) {//GEN-END:|72-getter|0|72-preInit
            // write pre-init user code here
            commandAbout = new Command("Hakk\u0131nda", Command.OK, 3);//GEN-LINE:|72-getter|1|72-postInit
            // write post-init user code here
        }//GEN-BEGIN:|72-getter|2|
        return commandAbout;
    }
    //</editor-fold>//GEN-END:|72-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form ">//GEN-BEGIN:|74-getter|0|74-preInit
    /**
     * Returns an initiliazed instance of form component.
     * @return the initialized component instance
     */
    public Form getForm() {
        if (form == null) {//GEN-END:|74-getter|0|74-preInit
            // write pre-init user code here
            form = new Form("HAKKINDA", new Item[] { getStringItem_owner(), getStringItem_developer(), getSpacer1(), getSpacer2(), getStringItem2(), getSpacer3(), getStringItem_note() });//GEN-BEGIN:|74-getter|1|74-postInit
            form.addCommand(getTamam1());
            form.setCommandListener(this);//GEN-END:|74-getter|1|74-postInit
            // write post-init user code here
        }//GEN-BEGIN:|74-getter|2|
        return form;
    }
    //</editor-fold>//GEN-END:|74-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem_developer ">//GEN-BEGIN:|76-getter|0|76-preInit
    /**
     * Returns an initiliazed instance of stringItem_developer component.
     * @return the initialized component instance
     */
    public StringItem getStringItem_developer() {
        if (stringItem_developer == null) {//GEN-END:|76-getter|0|76-preInit
            // write pre-init user code here
            stringItem_developer = new StringItem("Geli\u015Ftiren", "Erol HIRA");//GEN-BEGIN:|76-getter|1|76-postInit
            stringItem_developer.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);//GEN-END:|76-getter|1|76-postInit
            // write post-init user code here
        }//GEN-BEGIN:|76-getter|2|
        return stringItem_developer;
    }
    //</editor-fold>//GEN-END:|76-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem_owner ">//GEN-BEGIN:|77-getter|0|77-preInit
    /**
     * Returns an initiliazed instance of stringItem_owner component.
     * @return the initialized component instance
     */
    public StringItem getStringItem_owner() {
        if (stringItem_owner == null) {//GEN-END:|77-getter|0|77-preInit
            // write pre-init user code here
            stringItem_owner = new StringItem("S\u00F6zl\u00FCk Sahibi", "Prof. Dr. Mehmet KANAR");//GEN-BEGIN:|77-getter|1|77-postInit
            stringItem_owner.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);//GEN-END:|77-getter|1|77-postInit
            // write post-init user code here
        }//GEN-BEGIN:|77-getter|2|
        return stringItem_owner;
    }
    //</editor-fold>//GEN-END:|77-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem2 ">//GEN-BEGIN:|78-getter|0|78-preInit
    /**
     * Returns an initiliazed instance of stringItem2 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem2() {
        if (stringItem2 == null) {//GEN-END:|78-getter|0|78-preInit
            // write pre-init user code here
            stringItem2 = new StringItem("S\u00FCr\u00FCm", "1.0");//GEN-BEGIN:|78-getter|1|78-postInit
            stringItem2.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);//GEN-END:|78-getter|1|78-postInit
            // write post-init user code here
        }//GEN-BEGIN:|78-getter|2|
        return stringItem2;
    }
    //</editor-fold>//GEN-END:|78-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: spacer1 ">//GEN-BEGIN:|79-getter|0|79-preInit
    /**
     * Returns an initiliazed instance of spacer1 component.
     * @return the initialized component instance
     */
    public Spacer getSpacer1() {
        if (spacer1 == null) {//GEN-END:|79-getter|0|79-preInit
            // write pre-init user code here
            spacer1 = new Spacer(16, 5);//GEN-BEGIN:|79-getter|1|79-postInit
            spacer1.setLayout(ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            spacer1.setPreferredSize(-1, 5);//GEN-END:|79-getter|1|79-postInit
            // write post-init user code here
        }//GEN-BEGIN:|79-getter|2|
        return spacer1;
    }
    //</editor-fold>//GEN-END:|79-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: spacer2 ">//GEN-BEGIN:|80-getter|0|80-preInit
    /**
     * Returns an initiliazed instance of spacer2 component.
     * @return the initialized component instance
     */
    public Spacer getSpacer2() {
        if (spacer2 == null) {//GEN-END:|80-getter|0|80-preInit
            // write pre-init user code here
            spacer2 = new Spacer(16, 5);//GEN-BEGIN:|80-getter|1|80-postInit
            spacer2.setLayout(ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            spacer2.setPreferredSize(-1, 5);//GEN-END:|80-getter|1|80-postInit
            // write post-init user code here
        }//GEN-BEGIN:|80-getter|2|
        return spacer2;
    }
    //</editor-fold>//GEN-END:|80-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem_note ">//GEN-BEGIN:|81-getter|0|81-preInit
    /**
     * Returns an initiliazed instance of stringItem_note component.
     * @return the initialized component instance
     */
    public StringItem getStringItem_note() {
        if (stringItem_note == null) {//GEN-END:|81-getter|0|81-preInit
            // write pre-init user code here
            stringItem_note = new StringItem("Telif Hakk\u0131 Yoktur", "\u00DCcretsizdir. Ticari ama\u00E7la kullan\u0131lamaz. Kopyalan\u0131p da\u011F\u0131t\u0131labilir.");//GEN-BEGIN:|81-getter|1|81-postInit
            stringItem_note.setLayout(ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);//GEN-END:|81-getter|1|81-postInit
            // write post-init user code here
        }//GEN-BEGIN:|81-getter|2|
        return stringItem_note;
    }
    //</editor-fold>//GEN-END:|81-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: spacer3 ">//GEN-BEGIN:|82-getter|0|82-preInit
    /**
     * Returns an initiliazed instance of spacer3 component.
     * @return the initialized component instance
     */
    public Spacer getSpacer3() {
        if (spacer3 == null) {//GEN-END:|82-getter|0|82-preInit
            // write pre-init user code here
            spacer3 = new Spacer(16, 5);//GEN-BEGIN:|82-getter|1|82-postInit
            spacer3.setLayout(ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            spacer3.setPreferredSize(-1, 5);//GEN-END:|82-getter|1|82-postInit
            // write post-init user code here
        }//GEN-BEGIN:|82-getter|2|
        return spacer3;
    }
    //</editor-fold>//GEN-END:|82-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: Tamam1 ">//GEN-BEGIN:|83-getter|0|83-preInit
    /**
     * Returns an initiliazed instance of Tamam1 component.
     * @return the initialized component instance
     */
    public Command getTamam1() {
        if (Tamam1 == null) {//GEN-END:|83-getter|0|83-preInit
            // write pre-init user code here
            Tamam1 = new Command("Tamam", Command.OK, 0);//GEN-LINE:|83-getter|1|83-postInit
            // write post-init user code here
        }//GEN-BEGIN:|83-getter|2|
        return Tamam1;
    }
    //</editor-fold>//GEN-END:|83-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image1 ">//GEN-BEGIN:|86-getter|0|86-preInit
    /**
     * Returns an initiliazed instance of image1 component.
     * @return the initialized component instance
     */
    public Image getImage1() {
        if (image1 == null) {//GEN-END:|86-getter|0|86-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|86-getter|1|86-@java.io.IOException
                image1 = Image.createImage("/wait.png");
            } catch (java.io.IOException e) {//GEN-END:|86-getter|1|86-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|86-getter|2|86-postInit
            // write post-init user code here
        }//GEN-BEGIN:|86-getter|3|
        return image1;
    }
    //</editor-fold>//GEN-END:|86-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task1 ">//GEN-BEGIN:|90-getter|0|90-preInit
    /**
     * Returns an initiliazed instance of task1 component.
     * @return the initialized component instance
     */
    public SimpleCancellableTask getTask1() {
        if (task1 == null) {//GEN-END:|90-getter|0|90-preInit
            // write pre-init user code here
            task1 = new SimpleCancellableTask();//GEN-BEGIN:|90-getter|1|90-execute
            task1.setExecutable(new org.netbeans.microedition.util.Executable() {
                public void execute() throws Exception {//GEN-END:|90-getter|1|90-execute
                    Thread.sleep(3000);
                }//GEN-BEGIN:|90-getter|2|90-postInit
            });//GEN-END:|90-getter|2|90-postInit
            // write post-init user code here
        }//GEN-BEGIN:|90-getter|3|
        return task1;
    }
    //</editor-fold>//GEN-END:|90-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image ">//GEN-BEGIN:|93-getter|0|93-preInit
    /**
     * Returns an initiliazed instance of image component.
     * @return the initialized component instance
     */
    public Image getImage() {
        if (image == null) {//GEN-END:|93-getter|0|93-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|93-getter|1|93-@java.io.IOException
                image = Image.createImage("/giris.png");
            } catch (java.io.IOException e) {//GEN-END:|93-getter|1|93-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|93-getter|2|93-postInit
            // write post-init user code here
        }//GEN-BEGIN:|93-getter|3|
        return image;
    }
    //</editor-fold>//GEN-END:|93-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: waitScreen1 ">//GEN-BEGIN:|87-getter|0|87-preInit
    /**
     * Returns an initiliazed instance of waitScreen1 component.
     * @return the initialized component instance
     */
    public WaitScreen getWaitScreen1() {
        if (waitScreen1 == null) {//GEN-END:|87-getter|0|87-preInit
            // write pre-init user code here
            waitScreen1 = new WaitScreen(getDisplay());//GEN-BEGIN:|87-getter|1|87-postInit
            waitScreen1.setTitle("");
            waitScreen1.setCommandListener(this);
            waitScreen1.setFullScreenMode(true);
            waitScreen1.setImage(getImage());
            waitScreen1.setText("");
            waitScreen1.setTask(getTask1());//GEN-END:|87-getter|1|87-postInit
            // write post-init user code here
        }//GEN-BEGIN:|87-getter|2|
        return waitScreen1;
    }
    //</editor-fold>//GEN-END:|87-getter|2|
       
    public Display getDisplay () {

            return Display.getDisplay(this);
            // return Display.getDisplay (this);
    }

    public void exitMIDlet() {

            getDisplay().setCurrent(null);
            destroyApp(true);
            notifyDestroyed();
    }

    public TictionaryMIDlet() {
        initialize();
    }
    
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet ();
        } else {
            initialize ();
            getAboutStrings();
            initImageScr();
            startMIDlet ();
        }
        midletPaused = false;
    }
    
    protected void initImageScr(){
        
        Image img = null;
        
        try {
            img = Image.createImage("/wait.png");            
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        imgScr = new ImageScreen(img);
    }
    
    public void pauseApp() {
        midletPaused = true;
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    protected void searchText() {
        
        new Thread(){
            public void run(){
                search();
            }
        }.start();
    }        
    
    protected void search(){
        
        String word = getTextField().getString();
        
        String mean = "-";
        try {                    
            mean = searchFromBytes(word.trim());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
        mean = mean == null ? "-" : mean;
        
        addMeansToForm(mean);
    }    
       
    
    protected void clearMeanItems(){
        getForm1().deleteAll();
        getForm1().append(getTextField());
        getForm1().append(getSpacer());
    }
    
    protected void addMeansToForm(String mean){
        
        clearMeanItems();
        
        int tokenCount = StringUtils.getTokenCount(mean, ';');        
        
        for(int i = 0; i < tokenCount; i++){
            String token = StringUtils.getToken(mean, ';', i+1);
            token = tokenCount == 1 ? token : Integer.toString(i+1).concat(".").concat(token);
            StringItem item = new StringItem("", token);
            item.setLayout(ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_2);
            getForm1().append(item);
        }
    }
    
    protected void searchAdvanced(){
        
        switchDisplayable(null, imgScr);
        
        new Thread(){
            public void run(){
                advancedSearch();
            }
        }.start();
    }
    
    protected void advancedSearch() {
        
        String word = getTextField().getString();                
        
        try {                    
            searchMeans(word.trim());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
        
        if(resultVector != null && resultVector.size() > 0){
            
            getResultList().deleteAll();

            for(int i = 0; i < resultVector.size(); i++){
                getResultList().append((String) resultVector.elementAt(i), null);
            }
            
            switchDisplayable(null, getResultList());
            
        } else {
            clearMeanItems();
            switchDisplayable(null, getForm1());
        }
    }
    
    //-----------------------------------------------------------------------        
    
    protected String clipWord(String word){                        
        return word.substring(1);
    }
    
    protected byte[] getLetterDictBytes(String word) throws IOException{                
        
        return getBytesAsStreamFromFile(Utils.getDictFile(word.charAt(0), word.charAt(1)));
    }
    
    protected String searchFromBytes(String word) throws Exception{
        
        word = word.toLowerCase();
        
        ByteArray bytes = new ByteArray(getLetterDictBytes(word));
                
        word = clipWord(word);
        
        String result = null;
        
        for(int i = 0; i < word.length(); i++){
                
            byte chCount = bytes.readByte();
            
            char wordChar_i = word.charAt(i);
            
            for(int j = 0; j < chCount; j++){                                               
                
                byte ibyte = bytes.readByte();
                
                if(ibyte <= 33){
                    
                    StringBuffer buf = new StringBuffer();
                    for(int k = 0; k < ibyte; k++){
                        buf.append(Utils.getChar(bytes.readByte())); // array index out of bounds
                    }
                                        
                    if(word.substring(i).equals(buf.toString())){
                        int meanOffset = bytes.readShort();  // generally -1 of meanoffset gives exception
                        bytes.setOffset(meanOffset);
                        System.out.println("meanOffset: " + meanOffset);
                        result = bytes.readUTF(); // array index out of bounds
                        
                        return result;
                    } else {
                        bytes.readShort();
                    }
                    
                } else {
                    
                    char ch = Utils.getChar(ibyte);
                    int childsetOffset = bytes.readShort();
                    int meanOffset = bytes.readShort();
                    
                    if(wordChar_i == ch){                   

                        if(i == word.length()-1){

                            if(meanOffset < 0){
                                return null;
                            }

                            bytes.setOffset(meanOffset);
                            result = bytes.readUTF();

                            return result;

                        } else {

                            bytes.setOffset(childsetOffset);
                            break;
                        }
                    }
                }
                
                if(j == chCount -1) return null;
            }
        }
        
        return result;
    } 
    
    //--------------------------------------------------------------------
    
    String advancedWord;
    
    Vector resultVector;
    Vector meanOffsets;
    String meanBase;    
    
    protected void searchMeans(String word) throws Exception{
        
        resultVector = null;
        meanOffsets = null;
        
        meanBase = word.substring(0, word.length()-1);
        
        word = word.toLowerCase();
        
        advancedWord = word;
        getResultList().setTitle(advancedWord);
        
        ByteArray bytes = new ByteArray(getLetterDictBytes(word));
                
        word = clipWord(word);                
        
        String result = null;
        
        for(int i = 0; i < word.length(); i++){
                
            byte chCount = bytes.readByte();
            
            char wordChar_i = word.charAt(i);
            
            for(int j = 0; j < chCount; j++){                                               

                short childsetOffset = bytes.readShort();
                byte chByte = bytes.readByte();
                char ch = Utils.getChar(chByte);
                short meanOffset = bytes.readShort();

                if(wordChar_i == ch){

                    if(i == word.length()-1){
                        
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        DataOutputStream dbaos = new DataOutputStream(baos);
                        byte[] chBytes = new byte[127];
                        chOffset = 0;
                        chBytes[chOffset] = chByte;
                        chOffset ++;
                        meanCount = 0;
                        getMeans(bytes, dbaos, childsetOffset, meanOffset, chBytes);                                                
                        
                        setMeans(baos);
                        
                        return;
                        
                    } else {

                        bytes.setOffset(childsetOffset);
                        break;
                    }
                }
                
                if(j == chCount - 1) return;
            }
        }        
    }
    
    
    int chOffset;
    int meanCount;
    
    private void getMeans(ByteArray bytes, DataOutputStream out, short childsetOffset, short meanOffset, byte[] chBytes) throws IOException {
        
        if(meanOffset > 0){
            out.writeByte(2 + chOffset);
            out.writeShort(meanOffset);
            out.write(ByteArray.copyArray(chBytes, 0, chOffset));
            meanCount ++;
        }
        
        if(childsetOffset > 0){
            
            bytes.setOffset(childsetOffset);
            byte chCount = bytes.readByte();
            
            short[] childOffSets = new short[chCount];
            byte[] chs = new byte[chCount];
            short[] meanOffsets = new short[chCount];
            
            for(int i = 0; i < chCount; i++){
                childOffSets[i] = bytes.readShort();
                chs[i] = bytes.readByte();
                meanOffsets[i] = bytes.readShort();
            }
            
            for(int i = 0; i < chCount; i++){
                
                chBytes[chOffset] = chs[i];
                chOffset ++;                
                
                getMeans(bytes, out, childOffSets[i], meanOffsets[i], chBytes);
                
                chOffset --;
            }
        }
    }
    
    private String getMean() {
        
        try {
            
            ByteArray bytes = new ByteArray(getLetterDictBytes(advancedWord));
            
            bytes.setOffset(((Short)meanOffsets.elementAt(getResultList().getSelectedIndex())).shortValue());
            
            return bytes.readUTF();
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
        return "-";
    }
    
    private void setMeans(ByteArrayOutputStream baos) throws Exception {
        
        meanOffsets = new Vector(meanCount);
        resultVector = new Vector(meanCount);
        
        ByteArrayInputStream bain = new ByteArrayInputStream(baos.toByteArray());
        DataInputStream in = new DataInputStream(bain);                
        
        for(int i = 0; i < meanCount; i++){
            
            byte chCount = (byte) (in.readByte() - 2);
            meanOffsets.addElement(new Short(in.readShort()));
            
            byte[] meanChars = new byte[chCount];
            in.read(meanChars);
            
            String mean = meanBase;
            for(int j = 0; j < chCount; j++){
                mean += Utils.getChar(meanChars[j]);
            }
            
            resultVector.addElement(mean);
        }
        
        if(in != null){
            in.close();
        }        
    }

    
    //----------------------------------------------------------------
    
    private byte[] getBytesAsStreamFromFile(String file) throws IOException{
        
        DataInputStream in = new DataInputStream(getClass().getResourceAsStream(file));
        
        byte[] bytes = new byte[in.available()];
        
        int read = in.read(bytes);
        
        if(read < bytes.length){
            throw new IOException("read < bytes.length");
        }
        
        try {            
            in.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        return bytes;
    }
    
    private void getAboutStrings(){
        
        try {
            
            ByteArray about = new ByteArray(getBytesAsStreamFromFile("/zz.dat"));
            
            developer = about.readUTF();
            dev_mail = about.readUTF();
            dict_owner = about.readUTF();
            dictNote = about.readUTF();            
            
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}
